var ws = null;
var mqWs = null;
var wsObjs = [
    {"obj":mqWs,"url":getMQIP()}
];

function wsWithReConnect(wsObj,openFun,messageFun){
    if (wsObj.obj != null) {
        wsObj.obj.close();
        wsObj.obj = null;
    };
    wsObj.obj = new ReconnectingWebSocket(wsObj.url,null,{
        debug: true,
        reconnectInterval: 1000
    });

    wsObj.obj.onopen = openFun;
    wsObj.obj.onmessage = messageFun;
};

function wsWithReClose(wsObj){
    if (wsObj.obj != null) {
        wsObj.obj.close();
        wsObj.obj = null;
    };
};

function getMQIP () {
    // return java_url.replace("http://", "ws://") +"/beetle/mq/websocket";
};
function log(message,id) {
    if(id == ''){
        var divs = document.getElementsByName("logDiv");
        for(var i=0;i<divs.length;i++){
            divs[i].innerHTML+=message+'<br>';
            divs[i].scrollTop = divs[i].scrollHeight;
        };
    }else{
        var console = document.getElementById("logDiv_"+id);
        if( typeof console != undefined && console != null && console != ''){
            console.innerHTML+=message+'<br>';
            console.scrollTop = console.scrollHeight;
        };
    }
};